<?php
	session_start();
	
	if(isset($_GET["id"]))
	{
		$id = $_GET["id"];
		$sl = $_GET["sl"];
		
		//Truong hop chua khoi tao gio hang
		if(!isset($_SESSION["giohang"]))
		{
			$_SESSION["giohang"][] = $id;
			$_SESSION["soluong"][] = $sl;	
		}
		else //Truong hop gio hang da duoc khoi tao
		{
			//Tim trong gio hang co SP dang duoc chon chua, neu co roi thi tang so luong cua SP nay len
			for($i = 0; $i < count($_SESSION["giohang"]); $i++)
			{
				if($_SESSION["giohang"][$i] == $id)
					break;	
			}	
			
			if($i < count($_SESSION["giohang"]))
				$_SESSION["soluong"][$i] =  $_SESSION["soluong"][$i] + $sl;
			else
			{
				$_SESSION["giohang"][] = $id;
				$_SESSION["soluong"][] = $sl;	
			}
		}
	}
	
	header("location:".$_SESSION["urlHienTai"]);
?>